package com.adkun.community.config;

import com.adkun.community.controller.interceptor.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private AlphaInterceptor alphaInterceptor;

    @Autowired
    private LoginTicketInterceptor loginTicketInterceptor;

    @Autowired
    private MessageInterceptor messageInterceptor;

    @Autowired
    private DataInterceptor dataInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // Spring调用时会传入一个InterceptorRegistry对象
        // 我们用该对象注册拦截器
        registry.addInterceptor(alphaInterceptor) // 这样写会拦截所有请求
                .excludePathPatterns("**/*.css", "**/*.js", "**/*.png", "**/*.jpg", "**/*.jpeg") // 添加排除的拦截
                .addPathPatterns("/register", "/login"); // 添加需要拦截的地址（Controller）

        registry.addInterceptor(loginTicketInterceptor) // 这样写会拦截所有请求
                .excludePathPatterns("**/*.css", "**/*.js", "**/*.png", "**/*.jpg", "**/*.jpeg"); // 添加排除的拦截


        registry.addInterceptor(messageInterceptor)
                .excludePathPatterns("**/*.css", "**/*.js", "**/*.png", "**/*.jpg", "**/*.jpeg");

        registry.addInterceptor(dataInterceptor)
                .excludePathPatterns("**/*.css", "**/*.js", "**/*.png", "**/*.jpg", "**/*.jpeg");
    }
}
